<?php
header("Content-Type:text/html; charset=utf-8");
session_start();
if($_SESSION["islogin"]!=='igiveyouthepower'){
echo "<script language=JavaScript>\r\n";
echo "alert('请先登录');\r\n";
echo "location.href='../index.php'\r\n";
echo "</script>";
}else{
require_once('../config.php');
$conn = mysql_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd);
mysql_select_db($cfg_dbname,$conn);
header("Content-type:text/csv;charset=utf-8");
header("Content-Disposition:attachment;filename=aa.csv");
header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
header('Expires:0');
header('Pragma:public');
$datahead = "\xEF\xBB\xBFversion 1.00,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\r\ntitle,cid,seller_cids,stuff_status,location_state,location_city,item_type,price,auction_increment,num,valid_thru,freight_payer,post_fee,ems_fee,express_fee,has_invoice,has_warranty,approve_status,has_showcase,list_time,description,cateProps,postage_id,has_discount,modified,upload_fail_msg,picture_status,auction_point,picture,video,skuProps,inputPids,inputValues,outer_id,propAlias,auto_fill,num_id,local_cid,navigation_type,user_name,syncStatus,is_lighting_consigment,is_xinpin,foodparame,features,buyareatype,global_stock_type,global_stock_country,sub_stock_type,item_size,item_weight,sell_promise,custom_design_flag,wireless_desc,barcode,sku_barcode,newprepay,subtitle,cpv_memo,input_custom_cpv,qualification,add_qualification,o2o_bind_service
宝贝名称,宝贝类目,店铺类目,新旧程度,省,城市,出售方式,宝贝价格,加价幅度,宝贝数量,有效期,运费承担,平邮,EMS,快递,发票,保修,放入仓库,橱窗推荐,开始时间,宝贝描述,宝贝属性,邮费模版ID,会员打折,修改时间,上传状态,图片状态,返点比例,新图片,视频,销售属性组合,用户输入ID串,用户输入名-值对,商家编码,销售属性别名,代充类型,数字ID,本地ID,宝贝分类,用户名称,宝贝状态,闪电发货,新品,食品专项,尺码库,采购地,库存类型,国家地区,库存计数,物流体积,物流重量,退换货承诺,定制工具,无线详情,商品条形码,sku 条形码,7天退货,宝贝卖点,属性值备注,自定义属性值,商品资质,增加商品资质,关联线下服务";
function randomkeys($length)   
{   
   //$pattern = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ'; 
      $str = null;
      $strPol = "123456789";//大小写字母以及数字
      $max = strlen($strPol)-1;
      
      for($i=0;$i<$length;$i++){
         $str.=$strPol[rand(0,$max)];
      }
      return $str;
}
$lang=$_GET["lang"];
$bname=$_GET["bname"];
$cid=$_POST["cid"];
$seller_cids=$_POST["seller_cids"];
$location_state=$_POST["location_state"];
$location_city=$_POST["location_city"];
$valid_thru=$_POST["valid_thru"];//有效期
$post_fee=$_POST["post_fee"];
$ems_fee=$_POST["ems_fee"];
$has_showcase=$_POST["has_showcase"];//橱窗推荐
$postage_id=$_POST["postage_id"];
$outer_id=$_POST["outer_id"];
$user_name=$_POST["user_name"];
$features=$_POST["features"];
$data="";
if($_SESSION["thetype"]=="超级管理员"){$sql="select * from ph_".$lang." where 1=1";}
if($_SESSION["thetype"]=="管理员"){
$query="select admin from ph_admin where admin='".$_SESSION["managername"]."' or parent='".$_SESSION["managername"]."'";
$resulty=mysql_query($query);
$array=array();
while($rowy = mysql_fetch_array($resulty)){
array_push($array,"'".$rowy["admin"]."'");
}
$alluser=implode(',', $array);
$sql="select * from ph_".$lang." where 1=1 and user_name in(".$alluser.")";}
if($_SESSION["thetype"]=="员工"){$sql="select * from ph_".$lang." where 1=1 and user_name='".$_SESSION["managername"]."'";}
if($bname!==''&&isset($bname)){$sql.=" and bname ='".$bname."'";}
//echo $sql;
$result=mysql_query($sql);
$shuxingca=randomkeys(7);
while($row=mysql_fetch_array($result)){
  $shuxing="";
  $shuxingzhi="";
  $shuxingming="";
  $xiaoshou="";
  $imgs="";
  $r=0;
  $zhuangtai="";
  //主图
  $sqla="select * from ph_img where proid='".$row["ID"]."' and btid is null order by id,px asc";
	$resulta=mysql_query($sqla);
	while($rowa=mysql_fetch_array($resulta)){
     $imgs.=md5($rowa["ID"]).":1:".$r.":|http://".$_SERVER['SERVER_NAME'].$rowa["imgpath"].";";
     $zhuangtai.="1;";
     $r++;
	}
  $sqls="select * from ph_shuxing where proid='".$row["ID"]."' order by id asc";
  $results=mysql_query($sqls);
  while($rows=mysql_fetch_array($results)){
  	$shuxingma=randomkeys(10);
  	$shuxing.=$shuxingca.":".$shuxingma.";";
    $shuxingzhi.=$shuxingca.":".$shuxingma.":".$rows["cname"].";";
    $shuxingming.=$rows["cname"].";";
    $xiaoshou.=$rows["saleprice"].":".$rows["kucun"].":".$rows["skucode"].":".$shuxingca.":".$shuxingma.";";
    //分类图
    $sqlb="select * from ph_img where btid='".$rows["ID"]."' order by id asc";
	$resultb=mysql_query($sqlb);
	$i=0;
	while($rowb=mysql_fetch_array($resultb)){
       $imgs.=md5($rowb["ID"]).":2:".$i.":".$shuxingca.":".$shuxingma.":"."|http://".$_SERVER['SERVER_NAME'].$rowb["imgpath"].";";
       $zhuangtai.="1;";
       $i++;
	}
  }
  //处理图片

$data.='"'.$row["proname"].'"'.",".$cid.",".$seller_cids.",1,".$location_state.",".$location_city.",1,".$row["saleprice"].",0,".$row["kucun"].",".$valid_thru.",2,".$post_fee.",".$ems_fee.",0,0,0,1,".$has_showcase.",".date("Y-m-d H:i:s",time()).",".'"'.$row["content"].'"'.",".$shuxing.",".$postage_id.",0,".date("Y-m-d H:i:s",time()).",200,".$zhuangtai.",0,".$imgs.",,".$xiaoshou.",".$shuxingca.",".'"'.$shuxingming.'"'.",".$outer_id.",,0,".randomkeys(12).",0,2,".$user_name.",1,44,246,,".'"'.$features.'"'.",0,-1,,1,,,1,,,,,1,,,".'"'.$shuxingzhi.'"'.",%7B%7D,1,\r\n";

}
//echo $data;
echo $datahead."\r\n".$data;
}
?>